﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using Enter.Entity;
using Enter.Common;
using Enter.BizLogic;
using Enter.Web.SystemAdmin;
namespace WebSystemAdmin.sys
{
    public partial class OperatorEdit : PageBase
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            ListCtrlHelper.BindEnumOnListControl(ddl_Sex, typeof(Sys_OperatorEntity.EnumSex));
            ListCtrlHelper.BindEnumOnListControl(ddl_Status, typeof(Sys_OperatorEntity.EnumStatus));
            if (!IsPostBack)
            {
                if (Request.QueryString["ID"] != null)
                {
                    GetInfo();
                }
            }
        }

        private void GetInfo()
        {
            Sys_OperatorBLLSub bll = new Sys_OperatorBLLSub();
            Sys_OperatorEntity model = bll.GetObjectByID(int.Parse(Request.QueryString["ID"]));
            if (model == null) return;
            txt_ID.Text = model.ID.ToString();
            txt_LoginName.Text = model.LoginName.ToString();
            txt_UserName.Text = model.UserName.ToString();
            txt_Password.Text = model.Password.ToString();
            txt_DeptID.Text = model.DeptID.ToString();
            txt_EMail.Text = model.EMail.ToString();
            this.ddl_Sex.Items.FindByValue(((byte)model.Sex).ToString()).Selected = true;
            txt_Mobile.Text = model.Mobile.ToString();
            txt_Address.Text = model.Address.ToString();
            txt_Memo.Text = model.Memo.ToString();
            txt_RoleList.Text = model.RoleList.ToString();
            this.ddl_Status.Items.FindByValue(((byte)model.Status).ToString()).Selected = true;
        }

        protected void btnApply_Click(object sender, EventArgs e)
        {
            Sys_OperatorEntity model = new Sys_OperatorEntity();
            Sys_OperatorBLLSub bll = new Sys_OperatorBLLSub();
            if (Request.QueryString["ID"] != null)
            {
                model.ID = int.Parse(Request.QueryString["ID"]);
            }
            model.LoginName = txt_LoginName.Text;
            model.UserName = txt_UserName.Text;
            model.Password = txt_Password.Text;
            model.DeptID = txt_DeptID.Text;
            model.EMail = txt_EMail.Text;
            model.Sex = (Sys_OperatorEntity.EnumSex)byte.Parse(ddl_Sex.SelectedValue);
            model.Mobile = txt_Mobile.Text;
            model.Address = txt_Address.Text;
            model.Memo = txt_Memo.Text;
            model.RoleList = txt_RoleList.Text;
            model.Status = (Sys_OperatorEntity.EnumStatus)byte.Parse(ddl_Status.SelectedValue);
            if (bll.Save(model))
            {
                Utils.throwErrorGotoURL("添加成功", "OperatorList.aspx");
            }
            else
            {
                Utils.ShowMessage("添加失败");
            }
        }
    }
}
